#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<stdio.h>
#include<unistd.h>
#include<string.h>
#include<iostream>

int main(){

  //创建套接字

  //发送数据
  int sockfd= socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
  if(sockfd<0){
    return 0;
  }
  // struct sockaddr_in addra;
  // addra.sin_family=AF_INET;
  // addra.sin_port=htons(10001);
  // addra.sin_addr.s_addr=inet_addr("0.0.0.0");
  // bind(sockfd,(struct sockaddr*)&addra,sizeof(addra));

  struct sockaddr_in addr;
  addr.sin_family=AF_INET;
  addr.sin_port=htons(2927);
  addr.sin_addr.s_addr=inet_addr("43.143.149.122");
  while(1){
    char buf[1024]={0};

    printf("please to input:"); 
    // std::cout<<"please to input"<<std::endl;
    fflush(stdout);
    std::cin>>buf;
    sendto(sockfd,buf,strlen(buf),0,(struct sockaddr*)&addr,sizeof(addr));
    memset(buf,'\0',sizeof(buf));
    recvfrom(sockfd,buf,sizeof(buf)-1,0,NULL,NULL);
    printf("buf is :%s  \n",buf);
  }
  //   while(1){
  //   sleep(1);
  // }
  close(sockfd);
  return 0;

}
